package com.datastructure.test.maxvalue;

public class MaxValue {

    public static void main(String[] args) {
        MaxValue maxValue = new MaxValue();
        int value = maxValue.maxValue("321", 2);
        System.out.println(value);
    }

    public int maxValue (String s, int k) {
        // write code here
        int length = s.length();
        if(k>length){
            return -1;
        }
        int max = Integer.MIN_VALUE;
        for (int i = 0; i <=length-k; i++) {
            max = Math.max(max,Integer.parseInt(s.substring(i,i+k)));
        }
        return max;
    }
}
